<?php

namespace App\Models\Factory;


use App\Models\AbsModelFactory;
use App\Models\Orm\Rob;
use App\Models\Orm\UserBanks;
use App\Models\Orm\UserCertify;
use App\Models\Orm\UserIdentity;
use App\Models\Orm\UserProfile;
use App\Models\Orm\WelfareProduct;


/**
 * 意见反馈工厂
 * Class FeedbackFactory
 * @package App\Models\Factory
 */
class RobFactory extends AbsModelFactory
{


    /**
     * 存储文龙的数据
     */
    public static function rob($data)
    {
        $opinion = Rob::insert($data);
        return $opinion;
    }


    /**
     * 获取当天前十名用户
     */
    public static function getTopten()
    {
        $date = date("Y-m-d",time());
        $top = Rob::select('username','Lastapply','money')
            ->where(['money' => '20','Lastapply' => $date])
            ->orderby('id','desc')
            ->take(10)
            ->get()->toArray();
        foreach ($top as $key => $value){
            $top[$key]['username'] =  substr_replace($top[$key]['username'],'****','3','4');
        }
        return $top ? :[];
    }

    /**
     * 随机从数据库取出十条数据
     */
    public static function getRandomten($poor)
    {
        $top = Rob::select('username','Lastapply','money')
            ->where(['money' => '20'])
            ->orderByRaw('RAND()')
            ->take($poor)
            ->get()->toArray();
        foreach ($top as $key => $value){
            $top[$key]['username'] =  substr_replace($top[$key]['username'],'****','3','4');
        }
        return $top ? :[];
    }


    /**
     * 通过手机号获取用户领奖记录
     */
    public static function getRecord($data)
    {
        $record = Rob::where(['username' => $data])->get();
        return $record;
    }


    /**
     * 获取当天前一百名获奖名单
     */
    public static function getList()
    {
        $date = date("Y-m-d",time());
        $record = Rob::where(['money' => '20','Lastapply' => $date])->orderby('id','desc')->take(100)->get();
        foreach ($record as $key => $value){
            $record[$key]['username'] =  substr_replace($record[$key]['username'],'****','3','4');
        }
        return $record;
    }


    /**
     * 把文龙提供的产品数据保存进数据库
     */
    public static function addProduct($data)
    {
        $product = WelfareProduct::insert($data);
        return $product ? true : false;
    }


    /**
     * 把文龙提供的产品从数据库取出来
     */
    public static function GetProduct()
    {
        $product = WelfareProduct::where(['status' =>1])->get();
        return $product ? : [];

    }



}
